package com.xhs.utils;


import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

/**
 * @Auther: admin
 * @Date: 2021-10-15
 */
public class JedisUtils {
    public static final String HOST = "121.40.116.227";
    public static final Integer PORT = 6380;
    public static final String PASS = "qfjava";
    private static Jedis client;
    static {
        JedisPool pool = new JedisPool(HOST,PORT);
        client = pool.getResource();
        client.auth(PASS);
    }
    //新增
    public static void addStr(String key,String val,long seconds){
        client.setex(key,seconds,val);
    }
    public static void addSet(String key,String val){
        client.sadd(key,val);
    }
    public static void addList(String key,String val){
        client.lpush(key,val);
    }
    //查询
    public static String getStr(String key){
        return client.get(key);
    }
    public static boolean checkSet(String key,String val){
        return client.sismember(key,val);
    }
    //校验
    public static boolean checkKey(String key){
        return client.exists(key);
    }
    //返回剩余有效期
    public static long ttl(String key){
        return client.ttl(key);
    }
    //删除
    public static boolean delKey(String key){
        return client.del(key)>0;
    }
    public static boolean delSet(String key,String val){
        return client.srem(key,val)>0;
    }
    //设置key的有效期
    public static void expire(String key,long seconds){
        client.expire(key, seconds);
    }




}
